﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RATSharp.Validator
{
    class IntRangeInputValidator : IInputValidator<int>
    {
        private int min;
        private int max;
        public IntRangeInputValidator(int min, int max)
        {
            this.min = min;
            this.max = max;
        }


        public bool validate(string input, out int output)
        {
            output = 0;

            if (input == null)
            {
                return false;
            }

            try
            {
                int conv = Convert.ToInt32(input);
                if (conv < min || conv > max)
                {
                    return false;
                }
                output = conv;
                return true;
            }
            catch (FormatException ex)
            {
                return false;
            }
            catch (OverflowException ex)
            {
                return false;
            }
        }

    }
}
